package com.chat.controller;

import com.chat.service.ChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * Web控制器
 * 处理静态页面路由和API接口
 */
@Controller
public class WebController {
    
    @Autowired
    private ChatService chatService;
    
    /**
     * 首页 - 登录页面
     */
    @GetMapping("/")
    public String index() {
        return "index.html";
    }
    
    /**
     * 聊天页面
     */
    @GetMapping("/chat")
    public String chat() {
        return "chat.html";
    }
    
    /**
     * 获取聊天室状态信息API
     */
    @GetMapping("/api/status")
    @ResponseBody
    public Map<String, Object> getStatus() {
        Map<String, Object> status = new HashMap<>();
        status.put("onlineUsers", chatService.getOnlineUserCount());
        status.put("userList", chatService.getOnlineUsers());
        status.put("serverTime", java.time.LocalDateTime.now());
        status.put("status", "running");
        return status;
    }
    
    /**
     * 健康检查API
     */
    @GetMapping("/api/health")
    @ResponseBody
    public Map<String, String> health() {
        Map<String, String> health = new HashMap<>();
        health.put("status", "UP");
        health.put("service", "Chat Application");
        health.put("timestamp", java.time.LocalDateTime.now().toString());
        return health;
    }
}